<?php
/**
 * 课程目录
 * Class CourseAction
 */
class CourseAction extends CommonAction
{
    /**
     * 课程下面的信息
     */
    public function item()
    {
        $itemid = intval(I('get.itemid'));
        $this->checkEmpty($itemid, '标示不正确！');
        $course = M('Course')->find($itemid);
        $this->checkEmpty($course, '课程信息不存在！');
        $StudyModel = D('Study');
        $map['cid']= $itemid;
        import('ORG.Util.Page');
        $count = $StudyModel->where($map)->count();
        $Page = new Page($count,15);
        $studys = $StudyModel->limit($Page->firstRow.','.$Page->listRows)->where($map)->select();
        $this->assign('page', $Page->show());
        $this->assign('studys', $studys);
        $this->assign('course', $course);
        $this->display();
    }

    public function add() {
        
        $language = I('post.language');
        $level = I('post.level');

        $course = parent::_add(0,0,1);

        $data = array();
        $data['lang'] = $language;
        $data['lev'] = $level;
        $data['course'] = $course;

        $MapModel = D("Tag");
        $flag = $MapModel->add($data);

        if (!empty($flag)) { //保存成功
                $this->success('添加成功！');
        }

    }

    public function edit() {
        $isOk = parent::_edit(true);
        if($isOk){
            //修改tag
            //find
            //add OR update
            $TagModel = D('Tag');
            $rs = $TagModel->addOrUpdate($itemid, $lid, $levelId);
            
        }else{
            $this->error('修改失败！');
        }
        $this->display();
    }
}